<?php

namespace catchAdmin\pc\controller;

use catcher\base\CatchRequest as Request;
use catcher\CatchResponse;
use catcher\base\CatchController;
use catchAdmin\pc\model\News as NewsModel;
use think\Response;

class News extends CatchController
{

    protected $newsModel;


    /**
     *
     * @time 2025/08/13 18:10
     * @param NewsModel $newsModel
     * @return mixed
     */
    public function __construct(NewsModel $newsModel)
    {
        $this->newsModel = $newsModel;
    }


    /**
     *
     * @time 2025/08/13 18:10
     * @return Response
     */
    public function index(Request $request): Response
    {
        return CatchResponse::successPcList($this->newsModel->indexData($request->param()));
    }


    /**
     *
     * @time 2025/08/13 18:10
     * @param Request $request
     * @return Response
     */
    public function save(Request $request): Response
    {
        return CatchResponse::success($this->newsModel->saveData($request->post()));
    }


    /**
     *
     * @time 2025/08/13 18:10
     * @param $id
     * @return Response
     */
    public function read($id): Response
    {
        return CatchResponse::success($this->newsModel->findBy($id));
    }


    /**
     *
     * @time 2025/08/13 18:10
     * @param $id
     * @param Request $request
     * @return Response
     */
    public function update($id, Request $request): Response
    {
        return CatchResponse::success($this->newsModel->updateBy($id, $request->post()));
    }


    /**
     *
     * @time 2025/08/13 18:10
     * @param $id
     * @return Response
     */
    public function delete($id): Response
    {
        return CatchResponse::success($this->newsModel->deleteBy($id));
    }
}
